<%@ page contentType="text/html; charset=utf-8" %>
<%@ page language="java" pageEncoding="utf-8"%>

<%@ include file="header.jsp" %>
<body>
<div id="wynikiTestow" data-role="page" data-rockncoder-jspage="manageBarChart">  
	 
	 <header data-role="header" data-position="fixed">
    	<a href="userLogin!toMainPage.action"  data-icon="back" data-transition="fade">Powrót</a>
      	<h1>Wyniki</h1>
    </header>
    
    <section data-role="content">
     	<!-- Default text in popup -->
   		<div data-role="popup" id="popupWynikStyle" class="popupWynik"><p id="wynikTekst">Przepraszamy wystąpił błąd.</p></div>
    	
    	<center>
    		<div id="plotChart" class="myChart" style="height: 300px; width: 70%; margin: 30px;"></div>
		</center>
		<br>
		 <div>
			<table id="wynikiTable"> 
			  <thead> 
			    <tr> 
			      <th scope="col">Id:</th>  
			      <th scope="col">Punkty:</th>
			      <th scope="col">Data:</th> 
			    </tr> 
			  </thead> 
			  <tbody id="wyniki"> 


			  </tbody> 
			</table> 
	    </div>
	    
		<script>
			onload=wyniki();
			vals = [];
			ticksX = [];
			var oneWynik = 0;
			
			function wyniki(){
				 $.ajax(
						   {
						      type: "POST",
						      dataType: "json",
						      url: "testy!listWyniki.action",
						      success: function( response ) 
						      { 
						    	  result = new Array();
						    	  if(response.length == 0){
							        	$("p#wynikTekst").text("Brak wyników-proszę rozwiązać testy");
							       		$( "div.popupWynik" ).popup( "open", { overlayTheme: "a" } );
						    	  }else{
						    		  for (x=0; x<response.length; x++) {
							    		  result[x] = new Array();
							    		  result[x]['id'] = x+1;
							    		  result[x]['pt'] = response[x].pt;
							    		  result[x]['data'] = response[x].data;
							    		  
							    		  vals.push(result[x]['pt']);
							    		  ticksX.push([x+1,x+1]);
							    	  }
							    	  
							    	  //plat chart
							    	  $.jqplot('plotChart',[vals]).replot({
							    		    axesDefaults: {
											    pad: 0
											  },
							    		  axes:{
							    			  xaxis:{
							    				  padMin: 0,
							    				  label:"numer testu",
							    				  labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
							    				  ticks: ticksX
							    			  }, 
							    			  yaxis:{ 
							    				  
							    				  label:"punkty",
							    				  labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
							    				  labelOptions: {
							    			            fontFamily: 'Georgia, Serif',
							    			            fontSize: '12pt'
							    			          },
							    			      
							    			  }}, 
							    		 
							    		  });
							    	  
							    	  //table
									  for(var i = 0; i < result.length; i++){
										  var dates = new Date(result[i]['data']);
                                          var viewData = dates.getDate() + "-" + dates.getMonth() + 1 + "-" + dates.getFullYear();
						    			  $("#wyniki").append('<tr><td>'+ result[i]['id'] +'.</td><td>'+ result[i]['pt'] +'</td><td>'+ viewData +'</td></tr>');
						    		  }
						    		  
						    	  }
						      }
						   } );
				 if(oneWynik == 0){
					 location.reload();
					 oneWynik++;
				 }
			 }
			
		</script>
	
	
		

    </section>
    
    <div data-role="footer">
		<h4>E-PRAWO JAZDY</h4>
	</div>
</div>

</body>
</html>